level: intermediate
Brent is sharing two demos that show how to allow the user to drag a popup window. A popup has no titlebar, so it requires a little extra coding to make this possible.
Brent has released this code into the public domain with the following explanation.
Code
NoMainWin WindowWidth = 400 WindowHeight = 300 UpperLeftX = (DisplayWidth - WindowWidth) / 2 UpperLeftY = (DisplayHeight - WindowHeight) / 2 GraphicBox #demo.gfx, 0, 0, WindowWidth, WindowHeight StyleBits #demo.gfx, 0, _WS_BORDER, 0, 0 Open "Demo" For Dialog_Popup As #demo #demo "TrapClose demo.Close" #demo.gfx "When leftButtonMove demo.gfx.leftButtonMove" #demo.gfx "Down; Fill ButtonFace; BackColor ButtonFace" #demo.gfx "\\\ Try dragging me around!" #demo.gfx "\\ Press Alt+F4 to close." #demo.gfx "Flush" Wait Sub demo.Close demo$ Close #demo$ End End Sub Sub demo.gfx.leftButtonMove demo.gfx$, X, Y demo$ = Word$(demo.gfx$, 1, ".") CallDLL #user32, "ReleaseCapture", _ r As void hWnd = HWnd(#demo$) CallDLL #user32, "SendMessageA", _ hWnd As ULong, _ _WM_NCLBUTTONDOWN As ULong, _ _HTCAPTION As Long, _ 0 As Long, _ r As Long End Sub
Brent has also written a demo that uses WMLiberty.DLL to subclass a window and allow it to be dragged. The code is included in the zipped archive of this issue, because you must have the WMLiberty.DLL in the folder with the code in order to run it. Here is Brent's explanation of the second demo:
' This demo uses the WMLiberty DLL to trap the mouse's
' left-click in a popup-type window as a means to move
' the window around on the screen.